home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.src.lzh / input / newsrun < prev    next >
Text File  |  1980-01-01  |  3KB  |  141 lines

  1. #! /bin/sh
  2. # Process spooled news.
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/usr/lib/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/input:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH
  8. export PATH
  9.  
  10. umask $NEWSUMASK
  11.  
  12. here="$NEWSARTS/in.coming"
  13. cd $here
  14.  
  15. # First, is it worth trying at all?
  16. if test -r stop
  17. then
  18.     exit 0
  19. fi
  20.  
  21. # Lock against others running.
  22. lock="$NEWSCTL/LOCKinput"
  23. ltemp="$NEWSCTL/L.$$"
  24. echo $$ >$ltemp
  25. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  26. if newslock $ltemp $lock
  27. then
  28.     trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  29. else
  30.     exit 0
  31. fi
  32.  
  33. # Get rid of any old temporaries.
  34. rm -f nruntmp.*
  35. for f in `ls | egrep '^nspool'`
  36. do
  37.     find $f -mtime +1 -exec rm -f '{}' ';'
  38. done
  39.  
  40. # Sort out where we are.
  41. me="`hostname`"
  42. if test -r $NEWSCTL/server
  43. then
  44.     server=`cat $NEWSCTL/server`
  45. else
  46.     server="$me"        # no server file --> we're it
  47. fi
  48.  
  49. # Master loop.
  50. while true
  51. do
  52.     # Find some work.
  53.     them=`ls | egrep '^[0-9]+$' | sort | sed 50q`
  54.     if test "$them" = ""
  55.     then
  56.         break
  57.     fi
  58.  
  59.     # Do it.
  60.     for f in $them
  61.     do
  62.         # Check for request to stop.
  63.         if test -r stop
  64.         then
  65.             exit 0
  66.         fi
  67.  
  68.         # Check space.  It is *probably* better to stop processing
  69.         # when things get too full.  (This test is actually a bit
  70.         # inaccurate since the batch may be compressed, but it's
  71.         # good enough to catch major space problems.)
  72.         batchsize=`sizeof $f`
  73.         if test " $batchsize" -eq 0        # empty batch
  74.         then
  75.             rm -f $f
  76.             continue        # ugh
  77.         fi
  78.         if test " `spacefor $batchsize articles`" -le 0
  79.         then
  80.             exit 0
  81.         fi
  82.  
  83.         # Decompress if necessary.
  84.         text=nruntmp.$$
  85.         if compress -d <$f >$text 2>/dev/null
  86.         then
  87.             rmlist="$f $text"
  88.         elif c7decode <$f 2>/dev/null | compress -d >$text 2>/dev/null
  89.         then
  90.             rmlist="$f $text"
  91.         else
  92.             rm -f $text
  93.             text=$f
  94.             rmlist="$f"
  95.         fi
  96.  
  97.         # Do it.  -r redirects stdout and stderr into logs.  -n makes
  98.         # history entries for refused articles; this is right for
  99.         # NNTP-feed sites and doesn't hurt uucp-feed sites unless
  100.         # they refuse a good fraction of what they get.
  101.  
  102.         if test " $server" = " $me"    # if local
  103.         then
  104.             relaynews -r -n <$text
  105.         else
  106.             # N.B.: rsh always returns exit status 0!
  107.             rsh $server "PATH=$PATH relaynews -r -n" <$text
  108.         fi
  109.         st=$?
  110.         if test $st -ne 0
  111.         then
  112.             # trouble
  113.             if test ! -d bad
  114.             then
  115.                 mkdir bad
  116.             fi
  117.             bad=bad/$f
  118.  
  119.             if test -s bad/limit
  120.             then
  121.                 limit=`sed 1q bad/limit`
  122.             else
  123.                 limit=50
  124.             fi
  125.             nfiles=`ls bad | wc | awk '{print $1}'`
  126.             if test " $nfiles" -lt " $limit"
  127.             then
  128.                 mv $f $bad    # Not $text, save the ORIGINAL!
  129.             fi
  130.             echo "$server $consumer \`$bad' failed, status $st" |
  131.                             mail "$NEWSMASTER"
  132.         fi
  133.  
  134.         rm -f $rmlist
  135.     done
  136. done
  137.  
  138. find bad -mtime +7 -exec rm -f '{}' ';'
  139.  
  140. exit 0
  141.